import 'package:inmotion_pro/pages/models/user_model.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';
import 'package:safemap/safemap.dart';

enum ApplyOwnerStatus {
  applying(0), // 申请中，副车主发出申请等待车主处理
  success(1); // 申请成功，一般是当没有车主时，直接成为车主

  final int rawValue;
  const ApplyOwnerStatus(this.rawValue);
}

// 申请车主响应模型
class ApplyOwnerResponseModel extends BaseData {
  // 申请状态
  final ApplyOwnerStatus applyStatus;
  // 副车主申请时，会返回主车主基础信息
  final UserModel? ownerInfo;

  ApplyOwnerResponseModel({
    this.applyStatus = ApplyOwnerStatus.applying,
    this.ownerInfo,
  });

  factory ApplyOwnerResponseModel.fromJson(Map<String, dynamic> json) {
    SafeMap safeMap = SafeMap(json);
    return ApplyOwnerResponseModel(
      applyStatus: safeMap["status"].toInt == 1
          ? ApplyOwnerStatus.success
          : ApplyOwnerStatus.applying,
      ownerInfo: safeMap["owner"].map != null
          ? UserModel.fromMap(safeMap["owner"].map as Map<String, dynamic>)
          : null,
    );
  }
}
